{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2cd555fc",
   "metadata": {},
   "source": [
    "# LangChain接入嵌入模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c382791b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.embeddings import DashScopeEmbeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d5356558",
   "metadata": {},
   "outputs": [],
   "source": [
    "embeddings_model = DashScopeEmbeddings(\n",
    "    model=\"text-embedding-v4\",\n",
    "    dashscope_api_key=\"sk-da90821cf9174fbeb854011015c67aad\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "260f8e54",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将字符串进行词嵌入\n",
    "result = embeddings_model.embed_query(\"你好\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1b8ece6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将document进行词嵌入\n",
    "result = embeddings_model.embed_documents([\"你好\", \"大家好\"])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "learn_langchain",
   "language": "python",
   "name": "learn_langchain"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
